package com.tencent.cloud.uikit.ui.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tencent.cloud.uikit.R;

/**
 * 公共加载动画视图
 *
 * @author showxiao
 * @date 2018/9/26
 */
public class IovLoadingView extends LinearLayout {

    private TextView mLoadingTextView;

    public IovLoadingView(Context context) {
        super(context);
        init(context);
    }

    public IovLoadingView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public IovLoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.loading_view, this, true);
        mLoadingTextView = view.findViewById(R.id.tv_loading_text);
        setOrientation(VERTICAL);
        setGravity(Gravity.CENTER);
        setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
    }

    public void setText(CharSequence text) {
        mLoadingTextView.setText(text);
        mLoadingTextView.setVisibility(VISIBLE);
    }

    public void setText(@StringRes int resId) {
        mLoadingTextView.setText(resId);
        mLoadingTextView.setVisibility(VISIBLE);
    }

}
